package com.yunupmall.controller.ford;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunupmall.api.fordVO.EvaluateVO;
import com.yunupmall.api.fordentity.Evaluate;
import com.yunupmall.api.po.OrderCounts;
import com.yunupmall.service.ford.service.EvaluateService;
import com.yunupmall.uits.Result;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/evaluate")
@AllArgsConstructor
public class EvaluateController {
    private final EvaluateService evaluateService;
    private final Result result;
    @PostMapping("/save")
    public String saveData(@RequestParam(value = "grade",required = false) Integer grade,
                           @RequestParam(value = "text",required = false) String text,
                           @RequestParam(value = "orderId",required = false) Integer orderId,
                           @RequestParam(value = "falg",required = false) String falg){
        try {
            EvaluateVO evaluateVO = new EvaluateVO();
            evaluateVO.setGrade(grade);
            evaluateVO.setFalg(falg);
            evaluateVO.setOrderId(orderId);
            evaluateVO.setText(text);
            evaluateService.saveData(evaluateVO);
         return "udai_order";
        }catch (Exception e) {
          return e.getMessage();
        }
    }

    @PostMapping("/page")
    @ResponseBody
    public Result<Page<Evaluate>> pageData(@RequestBody EvaluateVO evaluateVO){
        try {
            return result.ok(evaluateService.pageData(evaluateVO));
        }catch (Exception e) {
            return result.error(e.getMessage());
        }
    }

    @GetMapping("/cumulative")
    @ResponseBody
    public Result<OrderCounts> Cumulative(Integer cId){
        try {
            return result.ok(evaluateService.cumulative(cId));
        }catch (Exception e) {
            return result.error(e.getMessage());
        }
    }
}
